function login(){
	var username=document.getElementById("username").value;
	var password=document.getElementById("password").value;
	if(username==""){
		alert("Please enter User ID");
		document.getElementById("username").focus();
		return false;
	}else if(password==""){
		alert("Please enter Password");
		document.getElementById("password").focus();
	}else{
		document.forms[0].submit();
		return false;
	}
	
}

function ChangeImage(path,currentindex,lastindex){
	document.getElementById("imageshow").src=path;
	document.getElementById("link").href=path;
	if(currentindex==lastindex){
		document.getElementById("imageshow").class="last";
	}else{
		document.getElementById("imageshow").class="";
	}
}
function deleteUpload(id){
	if(confirm("Are you sure you want to delete this file?")){
		window.location="delete_myupload.html?file_id="+id;
	}
}
function deleteFileUser(file_id,user_id){
	if(confirm("Are you sure you want to remove this user from share?")){
		window.location="delete_file_user.html?file_id="+file_id+"&user_id="+user_id+"";
		return true
	}
}
function deleteFileGroup(file_id,group_id){
	if(confirm("Are you sure you want to remove this group from share?")){
		window.location="delete_file_group.html?file_id="+file_id+"&group_id="+group_id+"";
		return true
	}
}

function addComment(e,com,item_id,divid) {
		 pre_data=document.getElementById(divid).innerHTML;
		 if (e.keyCode == 13){
			if(trim(com.value)==""){
				com.value="";
				alert("The comment can not be blank");
				com.focus();
			}else{
				//alert(pre_data);
		      	$.ajax({
		        url: 'add_comment.html',
		        data: "item_id=" + item_id + "&desc=" + com.value,
		        //data: ({desc : com.value}),
		        success: function(data) {
		          $('#'+divid).html(pre_data+data);
		          com.value="";
		          setTimeout(function(){$self();}, 10000);
		        }
		      });
			} 
		 }
}

function viewComment(item_id,divid) {
	      $.ajax({
	        url: 'view_comments.html',
	        data: "item_id=" + item_id,
	        //data: ({desc : com.value}),
	        success: function(data) {
	          $('#'+divid).html(data);
	        }
	      });
}

function insertTopic(url){
	if(trim(document.getElementById("itemdesc").value)==""){
		alert("The topic can not be blank");
		document.getElementById("itemdesc").value="";
		document.getElementById("itemdesc").focus();
	}else{
		document.forms[0].action=url;
		document.forms[0].submit();
	}
}
/* When User Press Enter to Post Topic*/
function newTopic(e,url){
	if (e.keyCode == 13){
		if(trim(document.getElementById("itemdesc").value)==""){
			alert("The topic can not be blank");
			document.getElementById("itemdesc").value="";
			document.getElementById("itemdesc").focus();
		}else{
			document.forms[0].action=url;
			document.forms[0].submit();
		}
	}
}
function trim(str) {
    return str.replace(/^\s+|\s+$/g,"");
}


function deleteGroup(id){
	if(confirm("Are you sure you want to delete this group?")){
		window.location="delete_group.html?group_id="+id;
	}
}

function viewMember(id){
	window.location="view_members.html?group_id="+id;
}

function deleteMember(group_id,user_id){
	if(confirm("Are you sure you want to remove this member?")){
		window.location="delete_member.html?group_id="+group_id+"&user_id="+user_id+"";
		return true
	}
}

function showDiv(showid,hideid,nameid){
	document.getElementById(showid).style.visibility="visible";
	document.getElementById(hideid).style.visibility="hidden";
	document.getElementById(nameid).focus();
	document.getElementById(nameid).select();
}
function closeDiv(showid,hideid,nameid){
	document.getElementById(showid).style.visibility="hidden";
	document.getElementById(hideid).style.visibility="visible";
}
function changeName(group_id,textid){
	var new_name=document.getElementById(textid).value;
	if(new_name==""){
		alert("The group name can not be blank");
		document.getElementById(textid).focus();
	}else{
		window.location="update_group.html?group_id="+group_id+"&group_name="+new_name;
	}
}
